﻿#pragma once
#include <memory>
#include <map>
#include <vector>
#include "co_generator.h"

struct MYSQL_RES;
struct MYSQL_FIELD;
namespace as
{
	namespace db
	{
		class MysqlResult : public std::enable_shared_from_this<MysqlResult>
		{
		public:
			MysqlResult(MYSQL_RES* res);
			~MysqlResult();
			void SetRes(MYSQL_RES* res);
			int GetFiledNum();
			std::vector<char*> GetVal(const char* key);

			// 辅助函数模板，用于处理每对参数
			template<typename T1, typename T2>
			T2 process_value(const T1& key, const T2& value) {
				// 这里可以根据 key 对 value 进行处理
				// 示例：如果 key 是整数，则 value 乘以 key
				if constexpr (std::is_integral_v<T1> && std::is_integral_v<T2>) {
					return value * key;
				}
				else if constexpr (std::is_same_v<T1, std::string> && std::is_same_v<T2, std::string>) {
					return value + " processed by " + key;
				}
				else {
					return value; // 默认返回原值
				}
			}

			// 辅助函数，用于递归展开参数包并处理每对参数
			template<typename... T1s, typename... T2s, std::size_t... Is>
			auto process_values_impl(const std::tuple<T1s...>& keys, const std::tuple<T2s...>& values, std::index_sequence<Is...>) {
				return std::make_tuple(process_value(std::get<Is>(keys), std::get<Is>(values))...);
			}

			// 主要的函数模板，接受两个相同长度的可变参数包
			template<typename... T1s, typename... T2s>
			auto process_values(const std::tuple<T1s...>& keys, const std::tuple<T2s...>& values) {
				static_assert(sizeof...(T1s) == sizeof...(T2s), "Two tuples must have the same length");
				return process_values_impl(keys, values, std::index_sequence_for<T1s...>{});
			}

			template<typename ...t1, typename __Type, typename ...params>
			bool get(std::tuple<t1...>& s, std::vector<std::tuple<__Type, params...> >& dest)
			{
				//GetVal()
			}


			MysqlResult* operator=(const MysqlResult* r);

		private:
			std::map<std::string, std::vector<char*> > keyToVal_;
			int field_num_ = 0;
			MYSQL_FIELD* field_;
			MYSQL_RES* result_;
		};
	}
}

